package itheima02;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

/**
 * @author xxx
 * @date 2020/12/26 18:44
 * @description
 */
public class Test1 {
    public static void main(String[] args) throws IOException {
        //创建客户端对象，指定端口号，发起连接
        Socket socket=new Socket("localhost",5555);
        //客户端向服务器发送消息调用字节输出流
        OutputStream outputStream=socket.getOutputStream();
        outputStream.write("食屎啦雷".getBytes());

        InputStream inputStream=socket.getInputStream();
        int b=0;
        byte[] bytes=new byte[1024];


        b=inputStream.read(bytes);
        System.out.println(new String(bytes,0,b));

        socket.close();
        outputStream.close();
    }
}

/*public class Test1 {
    public static void main(String[] args) throws Exception {
        System.out.println("客户端 发送数据");
// 1.创建 Socket ( ip , port ) , 确定连接到哪里.
        Socket client = new Socket("localhost", 6666);
// 2.获取流对象 . 输出流
        OutputStream os = client.getOutputStream();
// 3.写出数据.
        os.write("你好么? tcp ,我来了".getBytes());
// 4. 关闭资源 .
        os.close(); client.close(); }
}*/

